// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

// 删除重复元素
func removeDuplicates(array []int) int {
	if len(array) == 0 {
		return 0
	}
	last, finder := 0, 0
	for last < len(array)-1 {
		for array[finder] == array[last] {
			finder++
			if finder == len(array) {
				return last + 1
			}
		}
		array[last+1] = array[finder]
		last++
	}
	return last + 1
}

func main() {
	array := []int{5, 5, 6}
	res := removeDuplicates(array)
	fmt.Println(res)
}

//$ go run interview6-4.go
//2
